<template>
  <div class="total-container">
    <div v-if="!!topData" class="top-container">
      <div class="item-box" v-for="item in topData" :key="item.name">
        <div class="title">{{ item.name }}</div>
        <div class="value">
          <div class="num">
            <countTo :startVal="0" :endVal="item.num" :duration="1200" separator=""></countTo>
          </div>
          <div class="unit">{{ item.unit }}</div>
        </div>
      </div>
    </div>
    <div v-if="!!bottomData.data.data.length" class="bottom-container">
      <horizontalBar :chart-data="bottomData"></horizontalBar>
    </div>
  </div>
</template>
<script>
import horizontalBar from '../../charts/horizontalBar.vue'
import countTo from 'vue-count-to'
import { kjws } from '@/api/dongyingData'
export default {
  data() {
    return {
      topData: [
        {
          name: '全市学校数',
          num: 0,
          unit: '所'
        },
        {
          name: '专任教师总数',
          num: 0,
          unit: '人'
        },
        {
          name: '在校学生数',
          num: 0,
          unit: '人'
        }
      ],
      bottomData: {
        xAxis: { name: '单位：个', data: [] },
        yAxis: { name: '', data: [] },
        data: { name: '数量', data: [] },
        unit: '个'
      }
    }
  },
  components: {
    horizontalBar,
    countTo
  },
  mounted() {
    this.getData()
  },
  methods: {
    async getData() {
      const [res1, res2] = await Promise.all([kjws.educationData1(), kjws.educationData2()])
      this.topData[0].num = res1.result[0].qsxxs
      this.topData[1].num = res1.result[0].zrjszs
      this.topData[2].num = res1.result[0].zxxss
      res2.result.forEach(element => {
        this.bottomData.yAxis.data.push(element.fl)
        this.bottomData.data.data.push(element.sl)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.total-container {
  .top-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item-box {
      width: 132px;
      height: 53px;
      background: rgba(43, 101, 156, 0.3);
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #2b659c;
      padding-top: 5px;
      .title {
        font-family: MicrosoftYaHeiUI;
        font-size: 16px;
        color: #ffffff;
        line-height: 16px;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
      .value {
        display: flex;
        justify-content: center;
        align-items: baseline;
        margin-top: 5px;
        background: url('../../../img/left-row3-icon1.png') no-repeat center center;
        background-size: 127px 23px;
      }
      .num {
        font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
        font-weight: bold;
        font-size: 20px;
        color: #ffde00;
        line-height: 20px;
        text-align: right;
        font-style: normal;
        text-transform: none;
        background: radial-gradient(
          0deg,
          #ffffff 51%,
          #ffe5b9 54%,
          #ffc35b 100%
        );
      }
      .unit {
        font-family: MicrosoftYaHeiUI;
        font-size: 14px;
        color: #ffffff;
        line-height: 14px;
        text-align: center;
        font-style: normal;
        text-transform: none;
        margin-left: 3px;
      }
    }
  }
  .bottom-container {
    height: 150px;
  }
}
</style>
